<?php

namespace app\api\model;

use app\common\enums\StatusEnum;

class CustomerService extends \app\common\model\CustomerService
{
    /**
     * 客服列表
     * @param int $page 第几页
     * @param int $size 每页条数
     * @return array
     * @throws \think\Exception\DbException
     */
    public static function getList($page, $size)
    {
        $offset = ($page - 1) * $size;
        $where = [
            'status' => StatusEnum::ENABLED
        ];
        $model = static::field('id, name, nickname, sex, address, head_img AS headImg, qrcode')
            ->where($where)
            ->order(['sort_num' => 'desc', 'create_time' => 'desc'])
            ->limit($offset, $size)
            ->select()
            ->toArray();
        foreach ($model as $key => $value) {
            $model[$key]['headImg'] = config('file_prefix') . $value['headImg'];
            $model[$key]['qrcode'] = config('file_prefix') . $value['qrcode'];
        }

        $count = static::where($where)->count();
        return [
            'list' => $model,
            'count' => $count
        ];
    }

    /**
     * 获取客服列表
     * @return false|\think\db\Query[]
     * @throws \think\Exception\DbException
     */
    public static function getListAll()
    {
        return static::field('id, name')
            ->where(['status' => StatusEnum::ENABLED])
            ->order(['sort_num' => 'desc', 'create_time' => 'desc'])
            ->select()
            ->toArray();
    }
}